# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=py2exe
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=0.13.0.0
pkgrel=2
pkgdesc='A distutils extension to create standalone Windows programs from Python code (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
license=('MIT')
url='https://github.com/py2exe/py2exe'
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-cachetools
    ${MINGW_PACKAGE_PREFIX}-python-pefile
)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-cc
    ${MINGW_PACKAGE_PREFIX}-python-wheel)
source=(https://github.com/py2exe/${_realname}/archive/v${pkgver}.tar.gz
        001-setup-fix.patch
        002-mingw-fix.patch)
sha256sums=('a07b927460a86b45b78751d84fa1a28f0b6008e925edd34b61126f1ecfe1d60e'
            '80f69d375eb0dc33b21f9de9601ca6ee4b5e8c22e088101f96796bc22ecde19a'
            'fdf6fe050f6ca0cbc3f1c4136378e81b69ef3332a83e4d5bde72ad7228284be7')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  cd "${srcdir}/python-build-${MSYSTEM}"
  patch -p1 -i ${srcdir}/001-setup-fix.patch
  patch -p1 -i ${srcdir}/002-mingw-fix.patch
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
